//
//  BDCardInfoService.m
//  JingRong_Safe_IDLFaceSDKDemoOC
//
//  Created by Zhang,Jian(MBD) on 2021/10/21.
//  Copyright © 2021 Baidu. All rights reserved.
//

#import "BDCardInfoService.h"
#import "BDIDInfoAutoCollectController.h"
#import "BDIDInfoCollectController.h"
#import <BDFaceLogicLayer/BDFaceLogicLayer.h>
#import <BDFaceBaseKit/BDFaceBaseKit.h>
#import "BDFaceForUploadImageViewController.h"
#import "FaceParameterConfig.h"

@interface BDCardInfoService ()


@end

@implementation BDCardInfoService

+ (void)showCardCollectPage:(UIViewController *)controller finish:(void(^)(NSDictionary *dic))completion {
    NSString *type = [[NSUserDefaults standardUserDefaults] objectForKey:@"matchSource"];
    int sourceType = [type intValue];
    if (sourceType == 0) {
        if (use_OCR == 1) {
            // OCR 身份证识别页
            [self showOcrAutoInputController:controller finish:completion];
        } else if (use_OCR == 0) {
            // 手动输入页面
            [self showManualInputController:controller finish:completion];
        }
    } else {
        [self showMatchInputController:controller finish:completion];
    }
    
}

/// 显示手动输入页面
+ (void)showManualInputController:(UIViewController *)topController finish:(void(^)(NSDictionary *dic))completion {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"CollectInfo" bundle:[NSBundle mainBundle]];
    BDIDInfoCollectController *controller = [sb instantiateViewControllerWithIdentifier:@"BDIDInfoCollectController"];
    __weak UIViewController *weakTop = topController;
    [weakTop.navigationController pushViewController:controller animated:YES];
    controller.action = ^(NSDictionary * _Nonnull dic) {
        NSDictionary *parameters = [NSDictionary dictionaryWithDictionary:dic];
        if (completion) {
            completion(parameters);
        }
    };
}
/// 显示手动输入页面
+ (void)showMatchInputController:(UIViewController *)topController finish:(void(^)(NSDictionary *dic))completion {
    NSInteger type = [[NSUserDefaults standardUserDefaults] integerForKey:@"matchSource"];
    if (type == 0) {
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"CollectInfo" bundle:[NSBundle mainBundle]];
        BDIDInfoCollectController *controller = [sb instantiateViewControllerWithIdentifier:@"BDIDInfoCollectController"];
        __weak UIViewController *weakTop = topController;
        [weakTop.navigationController pushViewController:controller animated:YES];
        controller.action = ^(NSDictionary * _Nonnull dic) {
            NSDictionary *parameters = [NSDictionary dictionaryWithDictionary:dic];
            if (completion) {
                completion(parameters);
            }
        };
    } else {
        // 人脸对比本地上传相册图片示例代码
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Setting" bundle:[NSBundle mainBundle]];
        BDFaceForUploadImageViewController *controller = [sb instantiateViewControllerWithIdentifier:@"BDFaceForUploadImageViewController"];
        __weak UIViewController *weakTop = topController;
        [weakTop.navigationController pushViewController:controller animated:YES];
        controller.action = ^(NSDictionary * _Nonnull dic) {
            NSDictionary *parameters = [NSDictionary dictionaryWithDictionary:dic];
            if (completion) {
                completion(parameters);
            }
        };
    }
    
}

/// 显示OCR输入页面
+ (void)showOcrAutoInputController:(UIViewController *)topController finish:(void(^)(NSDictionary *dic))completion {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"CollectInfo" bundle:[NSBundle mainBundle]];
    BDIDInfoAutoCollectController *controller = [sb instantiateViewControllerWithIdentifier:@"BDIDInfoAutoCollectController"];
    __weak UIViewController *weakTop = topController;
    [topController.navigationController pushViewController:controller animated:YES];
    controller.action = ^(NSDictionary * _Nonnull dic) {
        NSDictionary *parameters = [NSDictionary dictionaryWithDictionary:dic];
        if (completion) {
            completion(parameters);
        }
    };
}


@end
